define(
	[
	appBasePath + '/scripts/module.js',
	],
	function (substanceModule) {

    'use strict';

    substanceModule.controller('Substance.UserMgrSettingController', [
        '$scope',
        '$state',
        '$stateParams',
        'gbits.websns.substance.config',
        'Substance.SettingService',
        '$timeout',
        function($scope, $state, $stateParams, config, settingService, $timeout) {
        	
        	// 默认待审批
        	$scope.page = {
        			currentPage: 1
        	};
        	
        	var ld = function loadData() {
        		$scope.list = [];
        		settingService.list({currentPage: $scope.page.currentPage}).then(function(data) {
        			$timeout(function(){
        				$scope.list = data.data;
            			$scope.page = data;
            			$scope.page.prePage = 1;
            			$scope.page.nextPage = data.lastPage;
            			if (data.currentPage > 1) {
            				$scope.page.prePage = data.currentPage - 1;
            			}
            			if (data.currentPage < $scope.page.lastPage - 1) {
            				$scope.page.nextPage = data.currentPage + 1;
            			}
            			$scope.page.showPages = [];
            			for (var i = data.currentPage - 5; i<=data.lastPage; i++) {
            				if (i>0) {
            					$scope.page.showPages.push(i);
            				}
            				if ($scope.page.showPages.length > 10) {
            					break;
            				}
            			}
        			})
        			
        		});
        	};
        	
        	$scope.setApproval = function(item, status) {
        		settingService.setApproveUser({userId: item.userId, userName: item.userName, state: status}).then(function(data){
        			$timeout(function(){
        				if (data.success) {
        					item.approveUser= data.data.approveUser;
        				}
        			});
        		});
        	};
        	
        	$scope.setAdmin = function(item, status) {
        		settingService.setManagerUser({userId: item.userId, userName: item.userName, state: status}).then(function(data){
        			$timeout(function(){
        				if (data.success) {
        					item.adminUser= data.data.adminUser;
        				}
        			});
        		});
        	};
        	
        	$scope.loadData = ld;
        	$scope.loadData();
        }
    ]);
});